import win32gui
import win32con
import pygetwindow

def activate_win(win):
    print('**AutoWorker** 置顶窗口前')
    # self.win.maximize()
    win32gui.ShowWindow(win._hWnd, win32con.SW_SHOWNORMAL)
    win32gui.BringWindowToTop(win._hWnd)
    # win.activate()
    win32gui.SetForegroundWindow(win._hWnd)
    # win32gui.SetActiveWindow(win._hWnd)
    # win32gui.BringWindowToTop(win._hWnd)
    print('**AutoWorker** 置顶窗口后')


def choice_win():
    wins = pygetwindow.getWindowsWithTitle('微信')
    if len(wins) == 1:
        win = wins[0]
    else:
        wins = pygetwindow.getWindowsWithTitle('无标题')
        win = wins[0]
    print('**AutoWorker** get wins', win)
    return win

win = choice_win()
activate_win(win)